﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;
namespace QuanLyDiem.Controllers
{
    public class C_Mon
    {
        public static void LoadDataSource(LookUpEdit lookupedit, Context db = null)
        {
            if (db == null) db = new Context();
            lookupedit.Properties.Columns.Clear();
            lookupedit.Properties.DataSource = db.MonHocs.OrderBy(a => a.Ten_mon).ToList();

            lookupedit.Properties.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("Ten_mon", "Tên môn"));
            lookupedit.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFit;

            lookupedit.Properties.DisplayMember = "Ten_mon";
            lookupedit.Properties.ValueMember = "ID_mon";
            lookupedit.Properties.NullText = "";
            lookupedit.ToolTip = lookupedit.Properties.NullValuePrompt = "Chọn môn";

            lookupedit.Properties.NullValuePromptShowForEmptyValue = true;
            lookupedit.Properties.AllowDropDownWhenReadOnly = DevExpress.Utils.DefaultBoolean.True;
            lookupedit.ItemIndex = 0;
        }
        public static void LoadDataSource(RepositoryItemLookUpEdit lookupedit, Context db = null)
        {
            if (db == null) db = new Context();

            lookupedit.Columns.Clear();
            lookupedit.DataSource = db.MonHocs.OrderBy(a => a.Ten_mon).ToList();
            lookupedit.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("Ten_mon", "Tên môn"));
            lookupedit.DisplayMember = "Ten_mon";
            lookupedit.ValueMember = "ID_mon";
            lookupedit.NullText = string.Empty;
            lookupedit.NullValuePrompt = string.Empty;
            lookupedit.NullValuePromptShowForEmptyValue = true;
            lookupedit.AllowDropDownWhenReadOnly = DevExpress.Utils.DefaultBoolean.False;
        }
    }
}
